<template>
    <el-row>
        <el-col :span="24">
            <el-form :inline="true"
                :model="letterSearchObj"
                class="search_prod tl">
                <el-form-item label="">
                    <el-input size="small"
                        clearable
                        v-model="letterSearchObj.content"
                        placeholder="站内信息"></el-input>
                </el-form-item>
                <el-form-item label="">
                    <el-input size="small"
                        clearable
                        v-model="letterSearchObj.nickname"
                        placeholder="用户昵称"></el-input>
                </el-form-item>
                <el-form-item label="">
                    <el-input size="small"
                        clearable
                        v-model="letterSearchObj.username"
                        placeholder="会员账户"></el-input>
                </el-form-item>
                <el-form-item label=""
                    class="time_width">
                    <el-date-picker v-model="createTime"
                        type="datetimerange"
                        size="small"
                        align="right"
                        unlink-panels
                        value-format="timestamp"
                        range-separator="-"
                        clearable
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :picker-options="pickerOptions2">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="">
                    <el-row class="tl">
                        <el-col :span="24">
                            <el-button :loading='$store.state.isLoading'
                                size="small"
                                class="top_weiy"
                                type="primary"
                                @click="onSubmit">查询</el-button>
                            <el-button :loading='$store.state.isLoading'
                                size="small"
                                class="top_weiy"
                                type="primary"
                                @click="delSubmit">一键清除</el-button>
                        </el-col>
                    </el-row>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
</template>
<script>
export default {
  name: "productSearch",
  data() {
    return {
      pickerOptions2: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      letterSearchObj: {
        nickname: "",
        content: "",
        username: "",
        created_time_begin: "",
        created_time_end: ""
      },
      createTime: []
    };
  },
  methods: {
    delSubmit() {
      this.letterSearchObj = {
        nickname: "",
        content: "",
        username: "",
        created_time_begin: "",
        created_time_end: ""
      };
      this.$emit("sendSearch", this.letterSearchObj);
    },
    onSubmit() {
      console.log(this.letterSearchObj);
      this.$emit("sendSearch", this.letterSearchObj);
    }
  },
  created() {},
  watch: {
    createTime(val) {
      if (val != null) {
        this.letterSearchObj.created_time_begin = this.$fnc.phptime(val[0]);
        this.letterSearchObj.created_time_end = this.$fnc.phptime(val[1]);
      } else {
        this.letterSearchObj.created_time_begin = "";
        this.letterSearchObj.created_time_end = "";
      }
    }
  }
};
</script>
